<template>
  <div>
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'CollapseGroup',
  props: {
    accordion: {
      type: Boolean,
      default: true
    },
    value: {}
  },
  data () {
    return {
      currentValue: []
    }
  },
  methods: {
    onToggle (data) {
      const index = this.currentValue.indexOf(data)
      if (index === -1) {
        if (this.accordion) this.currentValue = []
        this.currentValue.push(data)
      } else {
        this.currentValue.splice(index, 1)
      }
    }
  },
  watch: {
    value() {
      this.currentValue = this.value || []
    }
  }
}
</script>
